﻿/****************************************************************************
**
*****************************************************************************/

#ifndef MYLABEL_H
#define MYLABEL_H

#include <QWidget>
#include <QLabel>
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>

#include "mynamespace.h"

QT_BEGIN_NAMESPACE

class MyLabelPrivate;
class MyLabel : public QLabel
{
    Q_OBJECT

    Q_PROPERTY(int imageLayerIndex READ getImageLayerIndex WRITE setImageLayerIndex)

    Q_PROPERTY(int deviceIndex READ getDeviceIndex WRITE setDeviceIndex)

    Q_PROPERTY(My::ObjectType objectType READ getObjectType WRITE setObjectType)
    Q_PROPERTY(int objectIndex READ getObjectIndex WRITE setObjectIndex)
    Q_PROPERTY(double objectData READ getObjectData WRITE setObjectData)

    Q_PROPERTY(bool displayEnable READ getDisplayEnable WRITE setDisplayEnable)
    Q_PROPERTY(bool displayDefault READ getDisplayDefault WRITE setDisplayDefault)

    Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor)
    Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
    Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
    Q_PROPERTY(QColor myLabelBgColor READ getMyLabelBgColor WRITE setMyLabelBgColor)

public:
    explicit MyLabel(QWidget *parent = nullptr, Qt::WindowFlags f=Qt::WindowFlags());
    ~MyLabel();

    /* Property Interface */
    int getImageLayerIndex() const;
    void setImageLayerIndex(int imageLayerInd);

    int getDeviceIndex() const;
    void setDeviceIndex(int deviceInd);

    My::ObjectType getObjectType() const;
    void setObjectType(My::ObjectType);

    int getObjectIndex() const;
    void setObjectIndex(int);

    double getObjectData() const;
    void setObjectData(double);
    void setObjectData(int);

    bool getDisplayEnable() const;
    void setDisplayEnable(bool);

    bool getDisplayDefault() const;
    void setDisplayDefault(bool);

    QColor getBorderColor() const;
    void setBorderColor(const QColor &borderCol);

    int getBorderWidth() const;
    void setBorderWidth(int);

    int getBorderRadius() const;
    void setBorderRadius(int);

    QColor getMyLabelBgColor() const;
    void setMyLabelBgColor(const QColor &myLabelBgCol);

protected:
    void paintEvent(QPaintEvent *ev) override;
    void drawBorder(QPainter *painter);
    void drawBg(QPainter *painter);

    void enterEvent(QEvent *ev) override;
    void leaveEvent(QEvent *ev) override;
    void mousePressEvent(QMouseEvent *ev) override;
    void mouseReleaseEvent(QMouseEvent *ev) override;
    void mouseMoveEvent(QMouseEvent *ev) override;

private:
    Q_DISABLE_COPY(MyLabel)
    MyLabelPrivate *d;
};

QT_END_NAMESPACE

#endif // MYLABEL_H
